package com.campus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.campus.dao.CourseMapper;
import com.campus.entry.Course;
import com.campus.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public void createCourse(Course course) {
        courseMapper.insert(course);
    }

    @Override
    public Long countCourse() {
        LambdaQueryWrapper<Course> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        return courseMapper.selectCount(lambdaQueryWrapper);
    }

    @Override
    public Course getCourseById(Integer id) {
        return courseMapper.selectById(id);
    }

    @Override
    public List<Course> getCourseByTeacherId(Integer id) {
        return null;
    }

    @Override
    public List<Course> getCourseByTeacherId(Integer id, String status, String courseName) {
        LambdaQueryWrapper<Course> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Course::getTeacherId, id);
        if (status!=null&&!status.isEmpty()){
            lambdaQueryWrapper.eq(Course::getStatus,status);
        }
        if (courseName!=null&&!courseName.isEmpty()){
            lambdaQueryWrapper.like(Course::getCourseName,courseName);
        }
        return courseMapper.selectList(lambdaQueryWrapper);

    }

    @Override
    public void updateStatus(Integer id,String status) {
            courseMapper.updateStatusById(id,status);
    }

    @Override
    public void deleteCourseById(Integer id) {
        courseMapper.deleteById(id);
    }

    @Override
    public void updateCourse(Course course) {
        LambdaQueryWrapper<Course> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        courseMapper.updateById(course);
    }
}
